package com.zjk.exception;

import com.zjk.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * @author: gfk
 * @create: 2022/10/14
 * @Description:
 * @FileName: ProducctExceptionHandler
 * @History:
 * @自定义内容：
 */
@RestControllerAdvice
public class ProducctExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("调用了公共异常处理类");
        return new Result(false,2,e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result runTimeError(Exception e){
        e.printStackTrace();
        System.out.println("调用了runtimeException的公共异常处理类");
        return new Result(false,3,e.getMessage());
    }
    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result sqlError(Exception e){
        e.printStackTrace();
        System.out.println("调用了sql的公共异常处理类");
        return new Result(false,4,e.getMessage());
    }






}
